14 10 / 2013

Writing this down as I always forget this, and this search query is not very google friendly either (and I usually waste a lot of time looking for this, and probably so would others). This is how you do it:

sample_object.id.generation_time

Now the bonus stuff! If you wan to do range queries for created_at timestamp on the BSON id, this is how you do it:

Comments

14 12 / 2012

Problem: We wanted to add custom validation message, and call the same mysql table column with different names depending on the value of some other field. After much googling I couldn’t find any suitable answers. Posting the solution I came up with, so that it can be of help to others:

Solution: 

I couldn’t find solutions using procs, interpolations, etc. I wrote a custom validator, as all the columns are available there. Below is the sample code:

Please note that linktype and url are columns in the links table.

Also answered a related question on Stackoverflow here:

http://stackoverflow.com/questions/5085284/how-can-i-interpolate-ivars-into-rails-i18n-strings-during-validation/13881719#13881719

Comments
blog comments powered by Disqus